#define _CRT_SECURE_NO_WARNINGS 1
#define NUM 10
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
struct Node
{
	int arr[NUM];
	int index;
};
struct Node* Stack();
bool IsEmpty(struct Node* pStack);
void Push(struct Node* pStack, int a);
void FreeStack(struct Node** pStack);
int Top(struct Node* pStack);
void Pop(struct Node* pStack);
int main(void)
{
	struct Node* pStack = Stack();
	if (NULL == pStack)
		return 1;
	int arr[4] = { 1,2,3,4 };
	Push(pStack, arr[0]);
	Push(pStack, arr[1]);
	Push(pStack, arr[2]);
	Push(pStack, arr[3]);
	arr[0] = Top(pStack);
	Pop(pStack);
	arr[1] = Top(pStack);
	Pop(pStack);
	arr[2] = Top(pStack);
	Pop(pStack);
	arr[3] = Top(pStack);
	Pop(pStack);
	for (int i = 0; i < 4; i++)
	{
		printf("%d ", arr[i]);
	}
	FreeStack(&pStack);
	return 0;
}
void Pop(struct Node* pStack)
{
	if (IsEmpty(pStack))
		return;
	pStack->index--;
}
int Top(struct Node* pStack)
{
	if (IsEmpty(pStack))
		return 0;
	return pStack->arr[pStack->index - 1];
}
void FreeStack(struct Node** pStack)
{
	free(*pStack);
	*pStack=NULL;
}
void Push(struct Node* pStack, int a)
{
	if (pStack == NULL || NUM <= pStack->index)
		return;
	pStack->arr[pStack->index] = a;
	pStack->index++;
}
bool IsEmpty(struct Node* pStack)
{
	if (NULL == pStack || 0 == pStack->index)
		return true;
	return false;
}
struct Node* Stack()
{
	struct Node* ptemp = (struct Node*)malloc(sizeof(struct Node));
	if (ptemp == NULL)
		return NULL;
	ptemp->index = 0;
	return ptemp;
}